const componentsContext = require.context('@/components/global/', true, /\.vue$/)
const componentsBtns = require.context('@/components/globalBtn/', true, /\.vue$/)
import * as filters from '@/filters/filters'
import * as func from '@/utils/common'
import * as session from '@/utils/session'
import * as directives from '@/utils/directives'
export default {
	install(Vue) {
		//全局混入
		// Vue.mixin();
		//全局组件
		componentsContext.keys().forEach((component) => {
			const componentsConfig = componentsContext(component)
			const componentSelf = componentsConfig.default || componentsConfig
			if (componentSelf && componentSelf.name) {
				Vue.component(componentSelf.name, componentSelf)
			}
		})
		componentsBtns.keys().forEach((component) => {
			const componentsConfig = componentsBtns(component)
			const componentSelf = componentsConfig.default || componentsConfig
			if (componentSelf && componentSelf.name) {
				Vue.component(componentSelf.name, componentSelf)
			}
		})
		//全局过滤器
		Object.keys(filters).forEach((key) => {
			Vue.filter(key, filters[key])
		})
		//全局事件
		Object.keys(func).forEach((key) => {
			Vue.prototype[key] = func[key]
		})
		Object.keys(session).forEach((key) => {
			Vue.prototype[key] = session[key]
		})
		//定义全局指令
		Object.keys(directives).forEach((key) => {
			Vue.directive(key, directives[key])
		})
	},
}